import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/view/dataScreen/login.vue')
  },
  {
    path: '/',
    name: 'Home',
    component: () => import('@/view/dataScreen/index.vue'),
    meta:{
      isLogin:true
    }
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
});

router.beforeEach(async (to, from, next) => {
  if (to.meta.isLogin) {
    console.log(sessionStorage.getItem("isLogin"))
    if (sessionStorage.getItem("isLogin")==='success') {
      next();
    } else {
      next('/login');
    }
  } else {
    next();
  }
})

export default router
